<template>
	<!-- 审核对话框 -->
	<v-dialog v-model="ApprovalDialogModel.auditEquiDialog" width="600">
		<v-card>
			<v-card-title>审核</v-card-title>
			<v-card-text>
				<v-select v-model="approvalModel.approvalstatus" :items="ApprovalStatusItems" label="审批结果" outlined>
				</v-select>
				<v-textarea outlined name="input-7-4" label="回复" v-model="approvalModel.approvaldescription"
					:value="approvalModel.approvaldescription">
				</v-textarea>
			</v-card-text>
			<v-card-actions>
				<v-spacer></v-spacer>
				<v-btn color="success" class="mr-4" text @click="auditSubmit">确认</v-btn>
				<v-btn color="warning" class="mr-4" text @click="close">取消</v-btn>
			</v-card-actions>
		</v-card>
	</v-dialog>
</template>

<script>
	export default {
		name: 'audit_dialog',
		props: {
			callBack: {
				type: Function, //参数类型：函数
				default: () => {}
			},
			ApprovalDialogModel: {
				auditEquiDialog: false,
				//选择的项目
				selectList: [],
				//提交的地址
				submitUrl: ``,
			},
		},
		data: () => ({
			ApprovalStatusItems: [],
			approvalModel: {}
		}),
		watch: {
			ApprovalDialogModel: {
				handler(newVal) {
					this.$emit('update:ApprovalDialogModel', newVal)
					this.loadApprovalStatusItems()
				},
				deep: true
			},

		},
		methods: {
			async loadApprovalStatusItems() {
				if (!this.ApprovalDialogModel.auditEquiDialog) {
					return
				}
				var response = await this.$httpRequest({
					url: `MES/MESCommon/GetTypes`,
					method: 'post',
					data: ['ApprovalStatus']
				})
				if (response.status == 1) {
					this.ApprovalStatusItems = response.data.filter(r=>r.value==-1 ||r.value==99)
				}
			},
			async auditSubmit() {
				this.ApprovalDialogModel.selectList.forEach(r => {
					r.approvalstatus = this.approvalModel.approvalstatus
					r.approvaldescription = this.approvalModel.approvaldescription,
					r.approvalcategorytype= r.approval.approvalcategorytype
				})
				// `PDM/PDMEquiAudit/AuditEqui`,
				var response = await this.$httpRequest({
					url: this.ApprovalDialogModel.submitUrl,
					method: 'post',
					data: this.ApprovalDialogModel.selectList
				})
				if (response.status == 1) {
					this.$message.success(response.info)
					this.close()
					 this.$props.callBack()
				} else {
					this.$message.error(response.info)
				}
			},
			close() {
				this.approvalModel = {}
				this.ApprovalDialogModel.auditEquiDialog = false
			},
		}
	}
</script>
